
nodeflagperl = new Array();
for(i=0;i<80;i++)
{
	nodeflagperl[i] = 0;
}

function selectOnes()
{

}

function checkID()
{
  if(document.myform.showid.value=="")
  {
  	alert("Please choose a node at least!");
	return false;
  }
  var str=prompt("Please input password","******");
  if(str!="tinyos")
  {
  	alert("Wrong Password!");
	return false;
  }

return true;
}

function set_dot(i,j)// when clicked ,change color of dots
{
	var c=document.getElementById("coordiv");
	var cxt=c.getContext("2d");
	cxt.fillStyle="#00FF00";
	cxt.beginPath();
	cxt.arc(15+i*40,15+j*40,15,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
}

function cancel_dot(i,j)// when clicked ,change color of dots
{
	var c=document.getElementById("coordiv");
	var cxt=c.getContext("2d");
	cxt.fillStyle="#FF0000";
	cxt.beginPath();
	cxt.arc(15+i*40,15+j*40,15,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
}

function show()   //show init color
{
	var j;
	for(var i =0 ; i<8 ; i++)
	{
		for( j =0 ; j<10 ; j++)
		{
			var c=document.getElementById("coordiv");
			var cxt=c.getContext("2d");
			cxt.fillStyle="#FF0000";
			cxt.beginPath();
			cxt.arc(15+i*40,15+j*40,15,0,Math.PI*2,true);
			cxt.closePath();
			cxt.fill();
		}
	}
}

function getNode()
{

	//element=document.getElementById('myimage')

	//element.src="pic/downpic.jpg";


	var str="";
	for(i=0;i<80;i++)
	{
		if(nodeflagperl[i]==1)
		{
			str+=i;
			str+=",";
		}
	}
	//document.write(str);

	var c=document.getElementById('showid');
	c.value=str; 


}

function cnvs_getCoordinates(e) //when clicked ,get i,j
{
	x=e.clientX-150;
	y=e.clientY-80;

	for(var i=0;i<8;i++)
	{
		for(var j=0;j<10;j++)
		{
			tmpx=15+40*i;
			tmpy=15+40*j;
			if(((x-tmpx)*(x-tmpx)+(y-tmpy)*(y-tmpy))<=15*15)
			{
				var nodeid=i*10+j;
				if(nodeflagperl[nodeid]==1)
				{
					nodeflagperl[nodeid]=0;
					cancel_dot(i,j);
				}
				else if(nodeflagperl[nodeid]==0)
				{
					nodeflagperl[nodeid]=1;
					set_dot(i,j);
				}


				break;
			}
		}

	}
	document.getElementById("xycoordinates1").innerHTML="Clicked Node ID:" + nodeid ;
//	document.getElementById("xycoordinates").innerHTML="Clicked Node ID:::" + nodeid ;
}


function sensor_show(e) //when clicked ,get i,j
{
	x=e.clientX-150;
	y=e.clientY-80;
	var nodeid=-1;
	for(var i=0;i<8;i++)
	{
		for(var j=0;j<10;j++)
		{
			tmpx=15+40*i;
			tmpy=15+40*j;
			if(((x-tmpx)*(x-tmpx)+(y-tmpy)*(y-tmpy))<=15*15)
			{
				 nodeid=i*10+j;
				if(nodeflagperl[nodeid]==1)
				{
					nodeflagperl[nodeid]=0;
					cancel_dot(i,j);
				}
				else if(nodeflagperl[nodeid]==0)
				{
					nodeflagperl[nodeid]=1;
					set_dot(i,j);
				}


				break;
			}
		}

	}
	document.getElementById("search").value=nodeid;
	var formObj= document.getElementById("showsensor");
	formObj.submit();
}
function cnvs_clearCoordinates()  //when leave are ,clear x,y
{
	document.getElementById("xycoordinates").innerHTML="";
}
function printData(e)
{

}

